using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace vnMcdonald.Models.Mapping
{
    public class ImageMap : EntityTypeConfiguration<Image>
    {
        public ImageMap()
        {
            // Primary Key
            this.HasKey(t => t.ImageId);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(100);

            this.Property(t => t.Src)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("Images");
            this.Property(t => t.ImageId).HasColumnName("ImageId");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Src).HasColumnName("Src");
            this.Property(t => t.Order).HasColumnName("Order");
            this.Property(t => t.ProductId).HasColumnName("ProductId");
            this.Property(t => t.IsActive).HasColumnName("IsActive");

            // Relationships
            this.HasOptional(t => t.Product)
                .WithMany(t => t.Images)
                .HasForeignKey(d => d.ProductId);

        }
    }
}
